﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Data;
using NickLee.Common;

namespace GPCSC.Web.sjs
{
    public partial class DYBGS : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                fbuild();
            }
        }
        protected void fbuild()
        {
            this.MtxtD_tabid.Value = Guid.NewGuid().ToString();
            //this.MtxtD_hdid.Value = Usual.f_querystringToString("hdid");
            this.MtxtD_lgid.Value = Usual.f_querystringToString("lgid");
            byte[] userInfo = (byte[])base.o_baseTable[c_obj.s_userInfo];
            Hashtable userInfoTable = CompressData.UnCompressHashtable(userInfo);
            Model.CL_USER_S users = (Model.CL_USER_S)userInfoTable["SYS_USER"];
            this.MtxtD_lgname.Value = users.REALNAME.ToString();
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (MtxtD_dybg.Value.Trim() == "")
            {
                Response.Write("<script>alert('内容不能为空');</script>");
            }
            else
            {
                savenc();
            }
        }
        protected void savenc()
        {
            try
            {
                this.MtxtD_dybg.Value = this.MtxtD_dybg.Value.Replace("\n","^");
                Hashtable htable = f_getElements();
                SQLServerDAL.databyhtable dtable = new SQLServerDAL.databyhtable();

                dtable.databyhtables(htable, "add", "FK_DY", "", "");
                ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>showtable();</script>");


            }
            catch 
            {
                this.MtxtD_dybg.Value = new NotHTML().NoHTML(this.MtxtD_dybg.Value);
                Hashtable htable = f_getElements();
                SQLServerDAL.databyhtable dtable = new SQLServerDAL.databyhtable();

                dtable.databyhtables(htable, "add", "FK_DY", "", "");
                ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>showtable();</script>");
            }
        }

        public Hashtable f_getElements()
        {
            //UIFactory Get Values as Hashtable:界面工厂获取值，并保存在哈希表


            base.o_uiTable.Clear();
            base.o_uiTable = UIFactory.UIFactory_Get(this);
            return base.o_uiTable;
        }

        protected void LCallBack_Callback(object sender, NickLee.Web.UI.CallBackEventArgs e)
        {
            try
            {
                buidfile();
            }
            catch (Exception ee)
            {
                throw ee;
            }
            finally
            {
                Panel1.RenderControl(e.Output);
            }
        }
        /// <summary>
        /// 绑定新闻附件
        /// </summary>
        protected void buidfile()
        {
            try
            {

                Hashtable htable = new Hashtable();
                string file = this.MtxtD_tabid.Value;
                htable.Add("@NewsId", file);
                DataSet ds = new DataReturn().ReturnData(htable, "sel_newsfiles_all");
                if (ds != null)
                {
                    Repeater1.DataSource = ds;
                    Repeater1.DataBind();
                }

            }
            catch (Exception ee)
            {
                throw ee;
            }
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            try
            {
                if (MtxtD_dybg.Value.Trim() == "")
                {
                    Response.Write("<script>alert('内容不能为空');</script>");
                }
                else
                {
                    this.MtxtD_dybg.Value = this.MtxtD_dybg.Value.Replace("\n", "^");
                    Hashtable htable = f_getElements();
                    SQLServerDAL.databyhtable dtable = new SQLServerDAL.databyhtable();
                    htable.Add("isBs", 1);
                    dtable.databyhtables(htable, "add", "FK_DY", "", "");
                    ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>showtable();</script>");
                }


            }
            catch (Exception ee)
            {
                throw ee;
            }
        }
    }
}